Back to course home
0% completed
Vote For New Content
Google Hard
Shortest Subarray with Sum at Least K (hard)
Solution: Shortest Subarray with Sum at Least K
Reverse Pairs (hard)
Solution: Reverse Pairs
Nth Magical Number (hard)
Solution: Nth Magical Number
Candy (hard)
Solution: Candy
Arithmetic Slices II - Subsequence (hard)
Solution: Arithmetic Slices II - Subsequence
Burst Balloons (hard)
Solution: Burst Balloons
Sum of Distances in Tree (hard)
Solution: Sum of Distances in Tree
Maximum Score of a Good Subarray (hard)
Solution: Maximum Score of a Good Subarray
Trapping Rain Water (hard)
Solution: Trapping Rain Water
First Missing Positive (hard)
Solution: First Missing Positive
Minimum Difference Between Largest and Smallest Value in Three Moves (medium)
Problem Statement
You are given an integer array nums. You're allowed to change any of the numbers up to three times, turning them into any value you wish.
Return the minimum difference between the largest and smallest value of nums after updating the nums array.
Examples
-
Example 1:
- Input: [1,5,6,14,15]
- Expected Output: 1
- Justification: Change the numbers 14 and 15 to 2 and 3, respectively (or similarly small numbers). Now, the array is [1,2,3,5,6] with a minimum difference of 5 - 1 = 4.
-
Example 2:
- Input: [10,10,10,10,10]
- Expected Output: 0
- Justification: All numbers are the same, so even without any moves, the difference is already 0.
-
Example 3:
- Input: [1,100,200,300,400]
- Expected Output: 99
- Justification: Change the three highest values to any number between 1 and 100 (inclusive). For simplicity, changing 200, 300, and 400 to 2, 3, and 4 respectively will make the array [1,2,3,4,100], with a minimum difference of 100 - 1 = 99.
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Unique Length-3 Palindromic Subsequences
Solution: Minimum Difference Between Largest and Smallest Value in Three Moves
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself